﻿Partial Public Class GeneraXLS

    Public Sub XLS(ByRef Pg As Page, ByVal url As String, ByVal pk_id As String, ByVal NombreXls As String)

        Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(ConfigurationManager.AppSettings("urlexcel") & url & "?id=" & pk_id)
        request.Method = System.Net.WebRequestMethods.Http.Get
        Dim response As System.Net.HttpWebResponse = request.GetResponse()
        Dim reader As New System.IO.StreamReader(response.GetResponseStream())
        Dim tmp As String = reader.ReadToEnd()
        response.Close()

        Pg.Response.Clear()
        Pg.Response.Buffer = True
        Pg.Response.ContentType = "application/vnd.ms-excel"
        Pg.Response.AddHeader("Content-Disposition", "attachment;filename=" & NombreXls & ".xls")
        Pg.Response.Charset = "UTF-8"
        Pg.Response.ContentEncoding = Encoding.Default
        Pg.Response.Write(tmp)
        Pg.Response.End()

    End Sub

End Class
